const path = require('path')
const cors = require('koa-cors')
const views = require("koa-views")

const koa = require('koa')
const koaBody = require('koa-body')
const koaStatic = require('koa-static')

const errHandler = require('./errHandler')
const app = new koa()
const router = require('../router')
app.use(koaBody({
    multipart: true,
    formidable: {
        // 在配置选项option 不推荐使用相对路径
        // 在option 里的相对路径 不是相对的当前文件，他是相对process.cwd()即当前进程
        uploadDir: path.join(__dirname, '../upload'),
        keepExtensions: true
    }
}));
app.use(cors())
app.use(router.routes())
// 让服务访问图片地址
app.use(koaStatic(path.join(__dirname, '../upload')))
// app.use(koaStatic(__dirname + "../../public"))
app.use(koaStatic(__dirname + "../../public",{extensions:["html"]}))
app.on('error781', errHandler)
module.exports = app
